﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chinaer.WCF.Services;

namespace Chinaer.UI.MVC.Controllers
{
    public class ShangJiaController : Controller
    {
        //
        // GET: /ShangJia/

        public ActionResult Index()
        {
            return View();
        }

        public string SaveShangJia(DTO.ShangJiaDTO shangJiaDTO)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.RegisterShangJia(shangJiaDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        public string UpdateShangJia(DTO.ShangJiaDTO shangJiaDTO)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.UpdateShangJia(shangJiaDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        public string DeleteShangJia(string id)
        {
            ChinaerService chinaerService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaerService.DeleteShangJiaByID(id, "");
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        public ContentResult GetAllShangJias()
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.ShangJiaDTO> listShangJia = chinaerService.GetAllShangJias("");
            string jsonResult = Helper.JsonHelper.GetJson(listShangJia, listShangJia.Count);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }

    }
}
